package com.kaifamiao.tree;

import java.util.Objects;
import java.util.logging.Logger;

public class Goods {
	
	private final Logger logger = Logger.getLogger( this.getClass().getName() );

	private Integer id; // 商品编号
	private String name; // 商品名称
	private long price; // 商品价格(以分为单位)
	private int discount; // 商品折扣，比如 六折对应 60 、九五折对应 95
	private String units; // 商品数量单位
	
	public Goods() {
		super();
	}

	public Goods(Integer id, String name, long price, int discount, String units) {
		super();
		this.id = id;
		this.name = name;
		this.price = price;
		this.discount = discount;
		this.units = units;
	}

	@Override
	public int hashCode() {
		logger.info( "求商品的哈希码值" );
		return Objects.hash( id, name, price, discount , units);
	}
	
	@Override
	public boolean equals( Object o ) {
		logger.info( "判断是否其它商品相等" );
		// 首先判断参数是否为空
		if( o == null ) {
			return false ;
		}
		// 其次判断当前对象的地址是否与指定对象地址相同
		if( this == o ) {
			return true ;
		}
		// 其次判断当前对象的类型与指定对象的类型是否相同
		if( this.getClass() == o.getClass() ) {
			Goods p = (Goods) o ;
			return id != null && id.equals( p.id ) &&  
				   name != null && name.equals( p.name ) && 
				   price == p.price && 
				   discount == p.discount && 
				   units != null && units.equals( p.units ) ;
		}
		return false ;
	}
	
	@Override
	public String toString() {
		return "(" + id + ", " + name + ", " + price + ", " + discount + ", " + units + ")";
	}

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public long getPrice() {
		return price;
	}

	public void setPrice(long price) {
		this.price = price;
	}

	public int getDiscount() {
		return discount;
	}

	public void setDiscount(int discount) {
		this.discount = discount;
	}

	public String getUnits() {
		return units;
	}

	public void setUnits(String units) {
		this.units = units;
	}

}
